package vaccine.appointment.system.family.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum FamilyRelationshipEnum {
    FATHER(0, "父亲"),
    MOTHER(1, "母亲"),
    SPOUSE(2, "配偶"),
    CHILD(3, "子女"),
    SIBLING(4, "兄弟姐妹"),
    OTHER(5, "其他");

    private final Integer code;
    private final String description;

    /**
     * 根据名称获取枚举对象
     * @param name 名称
     * @return 枚举对象
     */
    public static FamilyRelationshipEnum forName(String name) {
        for (FamilyRelationshipEnum relationship : FamilyRelationshipEnum.values()) {
            if (relationship.name().equalsIgnoreCase(name)) {
                return relationship;
            }
        }
        return null;
    }

    /**
     * 根据code获取描述
     * @param code 类型码
     * @return 描述
     */
    public static String getDescByCode(Integer code) {
        if (code == null) {
            return "";
        }
        for (FamilyRelationshipEnum relationship : FamilyRelationshipEnum.values()) {
            if (relationship.getCode().equals(code)) {
                return relationship.getDescription();
            }
        }
        return "";
    }
}
